package com.smile.mqtt.manager;

import com.smile.mqtt.constant.BusinessConstants;
import com.smile.mqtt.process.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
@Lazy
public class BusinessManager {

    public static Map<String, AbstractBusinessProcess> map = new ConcurrentHashMap<>();


    @Autowired
    private DrcDownBusinessProcessor drcDownBusinessProcessor;

    @Autowired
    private DrcUpBusinessProcessor drcUpBusinessProcessor;

    @Autowired
    private EventsBusinessProcessor eventsBusinessProcessor;

    @Autowired
    private OsdBusinessProcessor osdBusinessProcessor;

    @Autowired
    private PropertySetBusinessProcessor propertySetBusinessProcessor;

    @Autowired
    private PropertySetReplyBusinessProcessor propertySetReplyBusinessProcessor;

    @Autowired
    private RequestsBusinessProcessor requestsBusinessProcessor;

    @Autowired
    private RequestsReplyBusinessProcessor requestsReplyBusinessProcessor;

    @Autowired
    private ServicesBusinessProcessor servicesBusinessProcessor;

    @Autowired
    private ServicesReplyBusinessProcessor servicesReplyBusinessProcessor;

    @Autowired
    private StateBusinessProcessor stateBusinessProcessor;

    @Autowired
    private StatusBusinessProcessor statusBusinessProcessor;

    @Autowired
    private StatusReplyBusinessProcessor statusReplyBusinessProcessor;

    @Autowired
    private EventsReplyBusinessProcessor eventsReplyBusinessProcessor;

    @PostConstruct
    public void init() {
        map.put(BusinessConstants.DRC_DOWN, drcDownBusinessProcessor);
        map.put(BusinessConstants.DRC_UP, drcUpBusinessProcessor);
        map.put(BusinessConstants.EVENTS, eventsBusinessProcessor);
        map.put(BusinessConstants.EVENTS_REPLY, eventsReplyBusinessProcessor);
        map.put(BusinessConstants.OSD, osdBusinessProcessor);
        map.put(BusinessConstants.PROPERTY_SET, propertySetBusinessProcessor);
        map.put(BusinessConstants.PROPERTY_SET_REPLY, propertySetReplyBusinessProcessor);
        map.put(BusinessConstants.REQUESTS, requestsBusinessProcessor);
        map.put(BusinessConstants.REQUESTS_REPLY, requestsReplyBusinessProcessor);
        map.put(BusinessConstants.SERVICES, servicesBusinessProcessor);
        map.put(BusinessConstants.SERVICES_REPLY, servicesReplyBusinessProcessor);
        map.put(BusinessConstants.STATE, stateBusinessProcessor);
        map.put(BusinessConstants.STATUS, statusBusinessProcessor);
        map.put(BusinessConstants.STATUS_REPLY, statusReplyBusinessProcessor);
    }


    public void dispatcher(String businessName, String data) {
        AbstractBusinessProcess put = map.get(businessName);
        put.process(data);
    }

}
